#pragma once
#include "sapi.h"

#include <vector>

class StreamReceiver :
	public ISpStream
{
public:
	StreamReceiver(void);
	~StreamReceiver(void);

	WAVEFORMATEX* cachedWaveFormat;

    HRESULT STDMETHODCALLTYPE SetBaseStream( 
        IStream *pStream,
        REFGUID rguidFormat,
        const WAVEFORMATEX *pWaveFormatEx);
    
    HRESULT STDMETHODCALLTYPE GetBaseStream( 
        IStream **ppStream);
    
    HRESULT STDMETHODCALLTYPE BindToFile( 
        /*  */ 
        __in_z  LPCWSTR pszFileName,
        SPFILEMODE eMode,
        /*  */ 
        __in_opt  const GUID *pFormatId,
        /*  */ 
        __in_opt  const WAVEFORMATEX *pWaveFormatEx,
        ULONGLONG ullEventInterest);
    
    HRESULT STDMETHODCALLTYPE Close( void);

    HRESULT STDMETHODCALLTYPE GetFormat( 
        __RPC__in GUID *pguidFormatId,
        __RPC__deref_in_opt WAVEFORMATEX **ppCoMemWaveFormatEx);

        /* [local] */ HRESULT STDMETHODCALLTYPE Seek( 
            /* [in] */ LARGE_INTEGER dlibMove,
            /* [in] */ DWORD dwOrigin,
            /* [out] */ ULARGE_INTEGER *plibNewPosition);
        
    HRESULT STDMETHODCALLTYPE SetSize( 
        /* [in] */ ULARGE_INTEGER libNewSize);
    
    /* [local] */ HRESULT STDMETHODCALLTYPE CopyTo( 
        /* [unique][in] */ IStream *pstm,
        /* [in] */ ULARGE_INTEGER cb,
        /* [out] */ ULARGE_INTEGER *pcbRead,
        /* [out] */ ULARGE_INTEGER *pcbWritten);
    
    HRESULT STDMETHODCALLTYPE Commit( 
        /* [in] */ DWORD grfCommitFlags);
    
    HRESULT STDMETHODCALLTYPE Revert( void);
    
    HRESULT STDMETHODCALLTYPE LockRegion( 
        /* [in] */ ULARGE_INTEGER libOffset,
        /* [in] */ ULARGE_INTEGER cb,
        /* [in] */ DWORD dwLockType);
    
    HRESULT STDMETHODCALLTYPE UnlockRegion( 
        /* [in] */ ULARGE_INTEGER libOffset,
        /* [in] */ ULARGE_INTEGER cb,
        /* [in] */ DWORD dwLockType);
    
    HRESULT STDMETHODCALLTYPE Stat( 
        /* [out] */ __RPC__out STATSTG *pstatstg,
        /* [in] */ DWORD grfStatFlag);
    
    HRESULT STDMETHODCALLTYPE Clone( 
        /* [out] */ __RPC__deref_out_opt IStream **ppstm);

    /* [local] */ HRESULT STDMETHODCALLTYPE Read( 
        /* [length_is][size_is][out] */ void *pv,
        /* [in] */ ULONG cb,
        /* [out] */ ULONG *pcbRead);
    
    /* [local] */ HRESULT STDMETHODCALLTYPE Write( 
        /* [size_is][in] */ const void *pv,
        /* [in] */ ULONG cb,
        /* [out] */ ULONG *pcbWritten);

    HRESULT STDMETHODCALLTYPE QueryInterface( 
        /* [in] */ REFIID riid,
        /* [iid_is][out] */ __RPC__deref_out void __RPC_FAR *__RPC_FAR *ppvObject);

    ULONG STDMETHODCALLTYPE AddRef( void);

    ULONG STDMETHODCALLTYPE Release( void);

	std::vector<short> samples;
	long firstWriteTime;

private:
	ULONG refCount;

};
